home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-01 | 2.6 KB | 60 lines | [TEXT/GEOL] |
- Item 1208133 29-May-90 10:50PDT
-
- From: ROSENSTEIN1 Rosenstein, Larry
-
- To: MADA2 MacApp Dev Assoc, Curtis Faith,IVC
-
- cc: MACAPP.TECH$ MacApp Technical
-
- Sub: Re: RE[3] Object Style
-
- Curtis:
-
- If a Get/Set method is monomorphic then the extra performance overhead (vs.
- direct field access) is just a procedure call with one parameter. Also, you
- automatically eliminate 1 jump table entry, and possibly 2 if all calls to the
- method are from the segment containing the method. (This is only in non-debug
- mode.)
-
- I agree with you that Get/Set methods are rarely the performance bottleneck.
- This is why it is important to do measurements and find out where the
- bottleneck actually is. (I think your performance conclusions aren't valid,
- however, because people know that performance of Get/Set methods isn't a
- problem on a 50MHz 030. A Mac Plus is probably 1/10 as fast, so on that
- machine only 200 Gets adds .01 seconds.)
-
- C++ inline functions have no space or time overhead compared to a direct field
- access. The code generated by GetSomeObject.DoSomeMethod and
- fSomeObject.DoSomeMethod should be identical if GetSomeObject is inline.
-
- It is important to realize that using inline functions in this case doesn't
- completely isolate the client from the implementation of the class. The code
- to access the field is compiled into the client, which means if the
- representation of the class changes, the client must be recompiled.
-
- Also, if you declare a virtual method as inline, the compiler will often not
- compile the method inline. So if you expect people to override the Get/Set
- method, then it probably won't help to make it inline. (That's OK because you
- are going to pay the method dispatching overhead anyway.)
-
- One drawback of an inline function is that their code is duplicated each time
- they are called. This isn't a problem in pure Get/Set function. Another
- drawback is that Object Pascal doesn't have inline, if you need to make the
- class usable from both languages.
-
- I have wrestled with the question of whether methods of a class should directly
- access its fields. In most cases, I do directly access fields, especially in
- C++, where I can make all the fields private. I'm not sure that having private
- Get/Set methods buys you much. You don't get any additional safety or
- cleanliness, and the function call syntax hides the fact that you are accessing
- a field.
-
- I think Neil is right about having a naming convention that distinguishes pure
- Get/Set methods from methods that are more complicated, but also access an
- object's attribute.
-
- Larry Rosenstein
-
-
-
-